package com.hfi.restful.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.*;
import java.io.IOException;

/**
 * @author ChangLiang
 * @date 2019/7/31
 */
//@Component
public class TimeFilter implements Filter {

    private Logger LOGGER = LoggerFactory.getLogger("timeFilterLogger");

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        LOGGER.info("time filter init");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
            ServletException {
        LOGGER.info("time filter start");
        long timeMillis = System.currentTimeMillis();
        chain.doFilter(request, response);
        LOGGER.info("time filter 耗时 " + (System.currentTimeMillis() - timeMillis) + "ms");
        LOGGER.info("time filter finish");
    }

    @Override
    public void destroy() {
        LOGGER.info("time filter destroy");
    }
}
